﻿using SAIM.Models;
using SAIM.Models.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using MvcFileUploader.Models;
using MvcFileUploader;
using Hangfire;
using Hangfire.SqlServer;
using SAIM.Models.DAL;

namespace SAIM.Controllers
{
    public class DownloadsController : Controller
    {
        // GET: Downloads
        public ActionResult Index()
        {
            return View();
        }

        //-------------------------VIDEO MIGRACION CORREO
        //--------------------------------------------Se ejecuta cuando se va descargar un archivo.------------------------------------------------
        public ActionResult GetAttachedFile(string id)
        {          
            string filePath, fileName;

            filePath = fileName = string.Empty;



            using (DownloadsBLL attachment = new DownloadsBLL())
            {
                attachment.GetAttachmentName(id, ref filePath, ref fileName);

                if (fileName == null)
                    throw new HttpException(404, "Page Not Found");


            }
            return File(Path.Combine(filePath + "\\" + fileName), "multipart/form-data", fileName);

        }

    }
}